var tests = [];

function test(testData){
    tests.push(testData);
}

function runTests(container){
    for(testInstance in tests){
        try{
            if(tests[testInstance].testMethod()){
                AddSucceded(tests[testInstance].title, container);
            }
            else{
                AddFailed(tests[testInstance].title,container);
            }
        }catch(err)
        {
            AddFailedWithError(tests[testInstance].title,container,err);
        }
    }
}

function AssertThrows(testFunction, exceptionType){
    return function(){
        try{
            testFunction()
        }catch(err){
            return true;
        }
        
        return false;
    }
}

function AddFailed(testTitle, container){
    var element = document.getElementById(container);
    var p = document.createElement("p");
    p.style.backgroundColor = "#EEDDDD";
    p.innerHTML = "FAILED " + testTitle;
    element.appendChild(p);
}

function AddFailedWithError(testTitle, container, error){
    var element = document.getElementById(container);
    var p = document.createElement("p");
    p.style.backgroundColor = "#EEDDDD";
    p.innerHTML = "[__________FAILED] " + testTitle + "<br/>WITH ERROR : " + error;
    element.appendChild(p);
}

function AddSucceded(testTitle, container){
    var element = document.getElementById(container);
    var p = document.createElement("p");
    p.style.backgroundColor = "#E0F3B2";
    p.innerHTML = "[PASSED__________] " + testTitle;
    element.appendChild(p);
}